#pragma once


#ifndef _DETECTTRACK_H_
#define _DETECTTRACK_H_
#include <iostream>
#include <opencv2/opencv.hpp>
#include<time.h>
#include"threadPooling.h"

class DETECTTRACK
{
public:


	DETECTTRACK();
	DETECTTRACK(CentroidTracking& centTrack, ThreadPool& pool);
	~DETECTTRACK(){}

	//cv::Ptr<cv::ORB> orb = cv::ORB::create(10, 1.2f, 8, 31, 0, 2, cv::ORB::HARRIS_SCORE, 31, 20);
	//cv::Ptr<cv::FastFeatureDetector> fast_small = cv::FastFeatureDetector::create(10, true, cv::FastFeatureDetector::TYPE_9_16);
	//cv::Ptr<cv::FastFeatureDetector> fast_big = cv::FastFeatureDetector::create(20, true, cv::FastFeatureDetector::TYPE_9_16);

	void fast_point(cv::Mat gray);
	double fast_get_thresh(cv::Mat gray);
	std::vector<cv::KeyPoint> fast_keypoints(cv::Mat gray);
	std::vector<std::vector<cv::Point>> calculate_contours(std::vector<std::vector<cv::Point>> contours, double thr1, double thr2, cv::Mat image);
	void get_sky_roi(cv::Mat image, std::vector<std::vector<cv::Point>>& out_contours, cv::Mat& edge_Scharr2);
	void get_sky_roi2(cv::Mat image, std::vector<std::vector<cv::Point>>& out_contours, cv::Mat& edge_Scharr2);
	
	std::vector<cv::Rect> get_sky_ob(std::vector<std::vector<cv::Point>>& out_contours, cv::Mat& edge_Scharr);
	cv::Point2i track_outsky_ob(cv::Rect& rect, cv::Mat& pre_img, cv::Mat& image, int val);
	void update(cv::Mat& image, cv::Rect& outRect);
	cv::Rect  update(cv::Mat& image);

private:
	CentroidTracking centTrack;
	int flag = 0;
	cv::Mat preimg;
	cv::Rect pre_track;
	cv::Point2i precentr;
	int missframe;
	int maxmissframe;
	int frameThresh = 1;
	ThreadPool pool;

	std::vector<std::vector<cv::Point>> tmp_contours; // for sky ROI contours cache
	std::vector<cv::Rect> tmp_trackes; // for tracke cache

	cv::Ptr<cv::ORB> orb;
	cv::Ptr<cv::FastFeatureDetector> fast_small;
	cv::Ptr<cv::FastFeatureDetector> fast_big;
	std::vector<cv::Point2f> track_history;
	double obAreaThreshS = 5;  // Ŀ����ڸ����
	double obAreaThreshM = 0.25;  // Ŀ��С����ͼ��1/4  ̫����ʲ���Ŀ��

	double whRatioThreshM = 6;//������ҪС�ڸ�ֵ
	double whRatioThreshS = 0.5;//������ҪС�ڸ�ֵ



};





#endif